﻿using System;
using System.Linq;

namespace USERS.CYT369.COM.DAL
{
    public class TermsService : USERS.CYT369.COM.DAL.DbContexts.BaseService<TermsService>
    {
        public TermsService() { }

        /// <summary>
        /// 协议列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public IQueryable<USERS.CYT369.COM.MODELS.Terms.Terms> GetTerms(int? type = null, string name = null)
        {
            var items = base.Get<USERS.CYT369.COM.MODELS.Terms.Terms>(c => c.IsPublished == true);
            if (type.HasValue)
            {
                items = items.Where(c => c.TermsTypeID == type.Value);
            }

            if (!string.IsNullOrEmpty(name))
            {
                items = items.Where(c => c.Name.Contains(name));
            }

            return items;
        }

        /// <summary>
        /// 获取单条协议
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public USERS.CYT369.COM.MODELS.Terms.Terms GetTermsByID(int id)
        {
            return base.GetOne<USERS.CYT369.COM.MODELS.Terms.Terms>(c => c.Id == id && c.IsPublished == true);
        }


        public IQueryable<USERS.CYT369.COM.MODELS.Terms.TermsType> GetTermsTypes()
        {
            var items = base.Get<USERS.CYT369.COM.MODELS.Terms.TermsType>();

            return items;
        }

    }
}
